﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ninject;
using Ninject.Modules;

using BlackBBS.Infrastructure.Logging;
using BlackBBS.Infrastructure.Repository;
using BlackBBS.Models.Data;
using System.Configuration;

namespace BlackBBS
{
    class Program
    {
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new SiteModule());
            
            Server bbs = new Server(kernel.Get<ILogger>(), kernel.Get<IServerRepository>());
            bbs.StartUp();

            ConsoleKeyInfo cki;
            Console.WriteLine("Press the Escape (Esc) key to quit: \n");
            do
            {
                cki = Console.ReadKey();
                Console.Write(" --- You pressed ");
                if ((cki.Modifiers & ConsoleModifiers.Alt) != 0) Console.Write("ALT+");
                if ((cki.Modifiers & ConsoleModifiers.Shift) != 0) Console.Write("SHIFT+");
                if ((cki.Modifiers & ConsoleModifiers.Control) != 0) Console.Write("CTL+");
                Console.WriteLine(cki.Key.ToString());
            } while (cki.Key != ConsoleKey.Escape);
            
            bbs.Shutdown();

        }

        #region "Ninject Setup"
            static IKernel _container;
            public static IKernel Container
            {
                get
                {
                    if (_container == null)
                    {
                        _container = new StandardKernel(new SiteModule());
                    }
                    return _container;
                }
            }

            internal class SiteModule : NinjectModule
            {
                public override void Load()
                {
                    Bind<ILogger>().To<NLogLogger>();
                    var dbStore = ConfigurationManager.AppSettings["dbstore"];
                    switch (dbStore.ToString().ToLower())
                    {
                        case "redis":
                            Bind<IServerRepository>().To<SiderServerRepository>();
                            break;

                        default:
                            Bind<IServerRepository>().To<XMLServerRepository>();
                            break;
                    }                    
                }
            }

        #endregion
    }
}
